<?php
class Frmcreator_Form_Form extends Engine_Form
{   
    protected $_form;
    
    public function setForm($form){
        $this->_form = $form;
    }    
    
    public function getForm(){
        return $_form;
    }
    
    public function init()
    {        
        if($this->_form){
            $this->setTitle($this->_form->getTitle());
            
            $elements = $this->_form->getElements();
            $order = 0;            
            foreach($elements as $element){
                if($element->element_type == 'title'){
                   $this->setTitle($element->label);
                   continue; 
                }
                if($element->element_type == 'description'){
                   $this->setDescription($element->description);
                   continue;
                }
                $order = $element->order;
                $this->addElement($element->getType(),  //Element Type
                    $element->getName(), //Element Name
                    $element->getAttributes() //More attributes
                );
            }
            
            //check if Submit button is added
            $sumit = $this->getElement('sumit');
            if(!$sumit){
                $order = $order + 1;
                $this->addElement('Button', 'submit', array(
                  'label' => 'Send',
                  'type' => 'submit',
                  'order' => $order
                ));
            }
        }
    }
}
